<?php


class SessionScript extends ScriptBase {


	/**
	 * 构造函数
	 *
	 */
	public function __construct(){
		
	}
	
	/**
	 * 函数功能：清除session 把过期用户踢下线
	 */
	public function clear(){
		$c_db_k 	= 'manager_session_user_key';
		$ncif		= n_api('nconfig')->get($c_db_k);
		$block_key	= $ncif[$c_db_k];
		
		$redisc001	= n_api('redis')->c001;
		
		$tmp = $redisc001->hmGetAll($block_key);
		$now = time();
		$com = n_api("common");
		if(!empty($tmp)){
			$db = n_api('mysql')->db001;
			foreach($tmp as $key=>$val){
				$tmp_el = $com->unserializesession($val);
				if(!isset($tmp_el['uid']) || (strtotime($tmp_el['stime'])+20*60)<$now){
					$my_log_id = isset($tmp_el['log_id'])?$tmp_el['log_id']:'';
					if(empty($my_log_id) && isset($tmp_el['uid'])){
						$myrow = $db->fetchFirst("SELECT * FROM manager_log WHERE uid={$tmp_el['uid']} ORDER BY id DESC LIMIT 1");
						$my_log_id = $myrow['id'];
					}
					if(!empty($my_log_id)){
						$db->update("manager_log",array("logout_time"=>time()),"id={$my_log_id}");
						$db->update("manager_main",array("isonline"=>'N'),"id={$tmp_el['uid']}");
					}
					$redisc001->hmDelete($block_key,$key);
				}
			}
		}
	}
	
	
	public function test(){
		global $_SESSION;
		$_SESSION['session_test'] = 'session-test';
		echo '<pre><br>---------------------<br>';
		echo 'test-session:';
		var_dump($_SESSION);
		echo '<br>---------------------<br></pre>';
	}
}


?>